<template>
	<!-- 添加低龄人员 -->
	<view class="building-add">
		<view class="add-head">
			<view class="head-left">
				<view class="head-left-1">上传图片</view>
				<view class="head-left-2">图片建议大小不超过2M</view>
			</view>
			<view class="head-right" @click="chooseImage">
				<image class="img" v-if="birthProveImg==''" src="../../../../static/icon/jia-.png"></image>
				<image class="img2" v-else :src="birthProveImg"></image>
			</view>
		</view>
		<view class="add-content">
			<navigator class="add-item" url="../../Public/People" hover-class="none">
				<view class="item-left">低龄人员<text>*</text></view>
				<view class="item-right">{{ userId_text }}</view>
			</navigator>
			<navigator class="add-item" url="../../Public/leagl" hover-class="none">
				<view class="item-left">父亲<text>*</text></view>
				<view class="item-right">{{ fatherId_text }}</view>
			</navigator>
			<navigator class="add-item" url="../../Public/import" hover-class="none">
				<view class="item-left">母亲<text>*</text></view>
				<view class="item-right">{{ motherId_text }}</view>
			</navigator>
			<view class="add-item">
				<view class="item-left">出生医院<text>*</text></view>
				<view class="item-right"><input v-model="birthHospitalName" placeholder-style="color:#999;font-size:26rpx" placeholder="请输入出生医院" /></view>
			</view>
			<view class="add-item">
				<view class="item-left">出生证明编号<text>*</text></view>
				<view class="item-right"><input v-model="birthProveCode" placeholder-style="color:#999;font-size:26rpx" placeholder="请输入出生证明编号" /></view>
			</view>
			<view class="add-item">
				<view class="item-left">出生日期<text>*</text></view>
				<view class="item-right" @click="show=true">{{ birthday }}</view>
			</view>
			<view class="add-item">
				<view class="item-left">是否办理户籍<text>*</text></view>
				<view class="item-right" @click="jnShow=true">{{ isTransactKoseki_text }}</view>
			</view>
		</view>
		<view class="btn">
			<view class="btn-1" @click="handleSubmit">保存</view>
		</view>
		
		<u-toast ref="uToast" />
		<!--生日 -->
		<u-picker mode="time" v-model="show" :params="params" @confirm="confirm"></u-picker>
		<!-- 是否办理户籍 -->
		<u-select v-model="jnShow" :list="jnList" @confirm="confirmJn"></u-select>
	</view>
</template>

<script>
	export default{
		data() {
			return{
				jnShow:false,
				show:false,
				jnList:[
					{
						value:true,
						label:'是'
					},
					{
						value:false,
						label:'否'
					}
				],
				params: {
					year: true,
					month: true,
					day: true
				},
				userId:'',
				userId_text:'请选择',
				birthHospitalName:'',// 出生医院
				birthProveCode:'',// 出生证明编号
				birthProveImg:'',
				birthday:'请选择',// 出生日期
				fatherId:'',
				fatherId_text:'请选择',
				motherId:'',
				motherId_text:'请选择',
				isTransactKoseki:'',// 是否办理户籍
				isTransactKoseki_text:'是',
				childrenInfoId:''
			}
		},
		onLoad(options) {
			this.childrenInfoId = options.id
		},
		mounted() {
			this.getChildrenInfoById()
		},
		onShow() {
			let User = uni.getStorageSync('people')
			this.userId_text = User.name
			this.userId = User.id
			let leagl = uni.getStorageSync('leagl')
			this.fatherId_text = leagl.name
			this.fatherId = leagl.id
			let importPer = uni.getStorageSync('importPer')
			this.motherId_text = importPer.name
			this.motherId = importPer.id
		},
		methods:{
			getChildrenInfoById() {
				let params = {
					childrenInfoId:this.childrenInfoId
				}
				this.$u.api.getChildrenInfoById(params)
					.then(res => {
						console.log(res)
						if(res.code == 200) {
							this.birthProveImg = res.result.birthProveImg
							this.userId = res.result.userId
							this.userId_text = res.result.userName
							this.birthday = res.result.birthday
							this.fatherId = res.result.fatherId
							this.fatherId_text = res.result.fatherName
							this.motherId = res.result.motherId
							this.motherId_text = res.result.motherName
							this.isTransactKoseki = res.result.isTransactKoseki
							if(res.result.isTransactKoseki == true) {
								this.isTransactKoseki_text = '是'
							} else {
								this.isTransactKoseki_text = '否'
							}
							this.birthHospitalName = res.result.birthHospitalName
							this.birthProveCode = res.result.birthProveCode
						}
					})
					.catch(err => {
						console.log(err)
					})
			},
			confirm(e) {
				this.birthday = e.year + '-' + e.month + '-' + e.day
			},
			confirmJn(e) {
				this.isTransactKoseki = e[0].value
				this.isTransactKoseki_text = e[0].label
			},
			// 上传图片
			chooseImage() {
				const self = this
				uni.chooseImage({
					count: 1,
					sizeType: ['compressed'],
					sourceType: ['album', 'camera'],
					success(res) {
						// console.log(res.tempFilePaths[0])
						uni.uploadFile({
							url: self.$u.http.config.uplodeUrl,
							filePath: res.tempFilePaths[0],
							name: 'file',
							success: (res) => {
								// console.log(JSON.parse(res.data))
								self.birthProveImg = JSON.parse(res.data).message
							},
							fail: (res) => {
								console.log(res)
								uni.showToast({
									icon:'none',
									title:'上传失败'
								})
							}
						})
					}
				})
			},
			// 提交
			handleSubmit() {
				if(this.birthProveImg == '') {
					return this.$refs.uToast.show({
						title: '请上传证明图片'
					})
				}
				if(this.userId == '') {
					return this.$refs.uToast.show({
						title: '请选择低龄人员'
					})
				}
				if(this.motherId == '') {
					return this.$refs.uToast.show({
						title: '请选择母亲'
					})
				}
				if(this.fatherId == '') {
					return this.$refs.uToast.show({
						title: '请选择父亲'
					})
				}
				if(this.birthday == '请选择') {
					return this.$refs.uToast.show({
						title: '请选择出生日期'
					})
				}
				if(this.birthHospitalName == '') {
					return this.$refs.uToast.show({
						title: '请填写出生医院'
					})
				}
				if(this.birthProveCode == '') {
					return this.$refs.uToast.show({
						title: '请填写出生证明编号'
					})
				}
				uni.removeStorageSync('people')
				uni.removeStorageSync('leagl')
				uni.removeStorageSync('importPer')
				let params = {
					birthHospitalName:this.birthHospitalName,
					birthProveCode:this.birthProveCode,
					birthProveImg:this.birthProveImg,
					birthday:this.birthday,
					fatherId:this.fatherId,
					isTransactKoseki:this.isTransactKoseki,
					motherId:this.motherId,
					userId:this.userId,
					id:this.childrenInfoId
				}
				console.log(params)
				this.$u.api.editChildrenInfo(params)
					.then(res => {
						console.log(res)
						if(res.code == 200) {
							uni.showToast({
								title:'修改成功',
								icon:'success'
							})
						}
					})
					.catch(err => {
						console.log(err)
						this.$refs.uToast.show({
							title: err.message
						})
					})
			}
		}
	}
</script>

<style lang="scss" scoped>
	.building-add{
		background-color: #f5f6f7;
		min-height: 100vh;
		.gridcontent{
			height: 40vh;
			width: 100%;
			padding: 20rpx;
			color: #333;
			font-size: 27rpx;
			text-align: left;
			.item{
				width: 100%;
				padding: 5rpx 40rpx;
				overflow-y: auto;
				.item1{
					padding: 5rpx 40rpx;
					.item2{
						padding: 5rpx 40rpx;
						.item3{
							padding: 5rpx 40rpx;
							.item4{
								padding: 5rpx 40rpx;
								
							}
						}
					}
				}
			}
		}
		.add-head{
			display: flex;
			justify-content: space-between;
			align-items: center;
			background-color: #fff;
			height: 180rpx;
			padding: 20rpx;
			.head-left{
				.head-left-1{
					color: #000;
					font-size: 28rpx;
					font-weight: 600;
				}
				.head-left-2{
					color: #999;
					font-size: 24rpx;
					margin-top: 20rpx;
				}
			}
			.head-right{
				background-color: #cecece;
				display: flex;
				justify-content: center;
				align-items: center;
				border-radius: 10rpx;
				width: 150rpx;
				height: 150rpx;
				.img{
					width: 50%;
					height: 50%;
				}
				.img2{
					width: 100%;
					height: 100%;
				}
			}
		}
		.add-content{
			margin-top: 20rpx;
			padding-bottom: 110rpx;
			.add-item{
				display: flex;
				// justify-content: space-between;
				align-items: flex-start;
				padding: 30rpx 20rpx;
				background-color: #fff;
				border-bottom: 1px solid #f4f1f1;
				.item-left{
					color: #333;
					font-size: 28rpx;
					flex: 2;
					text{
						color: #DD524D;
					}
				}
				.item-right{
					font-size: 27rpx;
					color: #999;
					display: flex;
					justify-content: flex-end;
					align-items: center;
					flex: 4;
					input{
						text-align: right;
					}
					input::placeholder{
					    font-size: 26rpx;
					    color: #999;
					}
					textarea{
						
					}
					text{
						display: inline-block;
						margin-left: 5rpx;
					}
				}
			}
		}
		.btn{
			width: 100%;
			height: 110rpx;
			display: flex;
			justify-content: center;
			align-items: center;
			color: #fff;
			font-size: 30rpx;
			background-color: #f4f1f1;
			position: fixed;
			bottom: 0;
			left: 0;
			border-top: 1px solid #CCE6FF;
			.btn-1{
				background-color: #007AFF;
				display: flex;
				justify-content: center;
				align-items: center;
				width: 600rpx;
				height: 80rpx;
				border-radius: 40rpx;
			}
		}
	}
</style>
